﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using YYTea.MOdel.Model;
using YYTea.ORM;
using YYTea.Services.IServices;

namespace YYTea.Services.Services
{
    public class UserinfoServices : IUserInfo
    {
        private readonly YYTeaContext _context;
        public UserinfoServices(YYTeaContext context)
        {
            this._context = context;
        }
        public async Task<List<UserInfo>> GetAllUser()
        {
            var allUser = await _context.UserInfos.ToListAsync();
            return allUser;
            //throw new NotImplementedException();
        }

        public async Task<UserInfo> GetUserById(string Id)
        {
            UserInfo user = new UserInfo();            
            if (Id == null)
            {
                return null;
            }
            var getUser = await _context.UserInfos.FirstOrDefaultAsync(f => f.Id == Convert.ToString(Id));
            return getUser;
        }

        public async Task<UserInfo> GetUserByName(string Name)
        {
            UserInfo user = new UserInfo();
            //if(Name =)
            var getUser = await _context.UserInfos.FirstOrDefaultAsync(f => f.UserName == Name || f.Email == Name);
            return getUser;
            //throw new NotImplementedException();
        }
    }
}
